home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 May: Tool Chest / Developer CD Series May 1996 (Tool Chest) (Apple Computer) (1996).iso / Tool Chest / Development Tools & Languages / Dylan Related / Mindy / Mindy 1.2 - portable sources / libraries / dylan / misc.dylan < prev    next >
Encoding:
Text File  |  1995-03-15  |  2.7 KB  |  92 lines  |  [TEXT/ttxt]

  1. module: Dylan
  2. rcs-header: $Header: misc.dylan,v 1.7 94/11/03 23:51:01 wlott Exp $
  3.  
  4. //======================================================================
  5. //
  6. // Copyright (c) 1994  Carnegie Mellon University
  7. // All rights reserved.
  8. // 
  9. // Use and copying of this software and preparation of derivative
  10. // works based on this software are permitted, including commercial
  11. // use, provided that the following conditions are observed:
  12. // 
  13. // 1. This copyright notice must be retained in full on any copies
  14. //    and on appropriate parts of any derivative works.
  15. // 2. Documentation (paper or online) accompanying any system that
  16. //    incorporates this software, or any part of it, must acknowledge
  17. //    the contribution of the Gwydion Project at Carnegie Mellon
  18. //    University.
  19. // 
  20. // This software is made available "as is".  Neither the authors nor
  21. // Carnegie Mellon University make any warranty about the software,
  22. // its performance, or its conformity to any specification.
  23. // 
  24. // Bug reports, questions, comments, and suggestions should be sent by
  25. // E-mail to the Internet address "gwydion-bugs@cs.cmu.edu".
  26. //
  27. //======================================================================
  28. //
  29. //  This file contains the stuff that doesn't quite fit anywhere else.
  30. //
  31.  
  32. define method identity (x)
  33.   x;
  34. end;
  35.  
  36. define method as (c :: <class>, thing)
  37.   if (instance?(thing, c))
  38.     thing;
  39.   else
  40.     error("%= cannot be converted to %=", thing, c);
  41.   end;
  42. end;
  43.  
  44. // The built-in "as(<symbol>...)" method only handles byte-strings.
  45. define method as(cls == <symbol>, str :: <string>)
  46.   as(<symbol>, as(<byte-string>, str));
  47. end method as;
  48.  
  49.  
  50. define constant \| =
  51.   method (#rest ignore)
  52.     error("| is syntax only and can't be used as a function.");
  53.   end;
  54.  
  55. define constant \& =
  56.   method (#rest ignore)
  57.     error("& is syntax only and can't be used as a function.");
  58.   end;
  59.  
  60. define constant \:= =
  61.   method (#rest ignore)
  62.     error(":= is syntax only and can't be used as a function.");
  63.   end;
  64.  
  65. define method make (c == <generic-function>,
  66.             #key debug-name, required: req, rest?, key, all-keys?)
  67.   let req = select (req by instance?)
  68.           <fixed-integer> =>
  69.         if (req < 0)
  70.           error("required: can't be negative: %d",
  71.             req);
  72.         end;
  73.             req;
  74.           <sequence> =>
  75.         do(rcurry(check-type, <type>), req);
  76.             size(req);
  77.         end;
  78.   if (instance?(key, <collection>))
  79.     do(rcurry(check-type, <symbol>), key);
  80.     if (rest?)
  81.       error("rest?: cannot be true when keywords are supplied.");
  82.     end;
  83.   elseif (key)
  84.     error("bogus value for key:, must be either #f or a "
  85.         "collection of symbols.");
  86.   elseif (all-keys?)
  87.     error("all-keys?: cannot be true as long as key: is #f.");
  88.   end;
  89.   make-generic-function(debug-name, req, rest?, key, all-keys?,
  90.             #(), <object>);
  91. end;
  92.